<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Introduction into Android Development</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../df/d65/tutorial_table_of_content_introduction.html">Introduction to OpenCV</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Introduction into Android Development </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../d7/d1e/tutorial_clojure_dev_intro.html">Introduction to OpenCV Development with Clojure</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../da/d2a/tutorial_O4A_SDK.html">OpenCV4Android SDK</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left">Vsevolod Glumov </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 3.0 </td></tr>
</table>
<dl class="section warning"><dt>Warning</dt><dd>This tutorial is deprecated.</dd></dl>
<p>This guide was designed to help you in learning Android development basics and setting up your working environment quickly. It was written with Windows 7 in mind, though it would work with Linux (Ubuntu), Mac OS X and any other OS supported by Android SDK.</p>
<p>If you encounter any error after thoroughly following these steps, feel free to contact us via <a href="https://groups.google.com/group/android-opencv/">OpenCV4Android</a> discussion group or OpenCV <a href="https://forum.opencv.org">Q&amp;A forum</a>. We'll do our best to help you out.</p>
<h2>Preface </h2>
<p>Android is a Linux-based, open source mobile operating system developed by Open Handset Alliance led by Google. See the <a href="http://www.android.com/about/">Android home site</a> for general details.</p>
<p>Development for Android significantly differs from development for other platforms. So before starting programming for Android we recommend you make sure that you are familiar with the following key topis:</p>
<ol type="1">
<li><a href="http://en.wikipedia.org/wiki/Java_(programming_language)">Java</a> programming language that is the primary development technology for Android OS. Also, you can find <a href="http://docs.oracle.com/javase/">Oracle docs on Java</a> useful.</li>
<li><a href="http://en.wikipedia.org/wiki/Java_Native_Interface">Java Native Interface (JNI)</a> that is a technology of running native code in Java virtual machine. Also, you can find <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/">Oracle docs on JNI</a> useful.</li>
<li><a href="http://developer.android.com/training/basics/activity-lifecycle/starting.html">Android Activity</a> and its lifecycle, that is an essential Android API class.</li>
<li>OpenCV development will certainly require some knowledge of the <a href="http://developer.android.com/guide/topics/media/camera.html">Android Camera</a> specifics.</li>
</ol>
<h2>Manual environment setup for Android development </h2>
<h3>Development in Java</h3>
<p>You need the following software to be installed in order to develop for Android in Java:</p>
<ol type="1">
<li><p class="startli"><b>Sun JDK 6</b> (Sun JDK 7 is also possible)</p>
<p class="startli">Visit <a href="http://www.oracle.com/technetwork/java/javase/downloads/">Java SE Downloads page</a> and download an installer for your OS.</p>
<p class="startli">Here is a detailed JDK (Java Development Kit) <a href="http://source.android.com/source/initializing.html#installing-the-jdk">installation guide</a> for Ubuntu and Mac OS (only JDK sections are applicable for OpenCV)</p>
<dl class="section note"><dt>Note</dt><dd>OpenJDK is not suitable for Android development, since Android SDK supports only Sun JDK. If you use Ubuntu, after installation of Sun JDK you should run the following command to set Sun java environment: <div class="fragment"><div class="line">sudo update-java-alternatives --set java-6-sun</div></div><!-- fragment --></dd></dl>
</li>
<li><p class="startli"><b>Android SDK</b></p>
<p class="startli">Get the latest Android SDK from <a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a></p>
<p class="startli">Here is Google's <a href="http://developer.android.com/sdk/installing.html">install guide</a> for the SDK.</p>
<dl class="section note"><dt>Note</dt><dd>You can choose downloading <b>ADT Bundle package</b> that in addition to Android SDK Tools includes Eclipse + ADT + NDK/CDT plugins, Android Platform-tools, the latest Android platform and the latest Android system image for the emulator - this is the best choice for those who is setting up Android development environment the first time!</dd>
<dd>
If you are running x64 version of Ubuntu Linux, then you need ia32 shared libraries for use on amd64 and ia64 systems to be installed. You can install them with the following command: <div class="fragment"><div class="line">sudo apt-get install ia32-libs</div></div><!-- fragment --> For Red Hat based systems the following command might be helpful: <div class="fragment"><div class="line">sudo yum install libXtst.i386</div></div><!-- fragment --></dd></dl>
</li>
<li><p class="startli"><b>Android SDK components</b></p>
<p class="startli">You need the following SDK components to be installed:</p><ul>
<li><p class="startli"><em>Android SDK Tools, revision 20</em> or newer.</p>
<p class="startli">Older revisions should also work, but they are not recommended.</p>
</li>
<li><p class="startli"><em>SDK Platform Android 3.0</em> (API 11).</p>
<p class="startli">The minimal platform supported by OpenCV Java API is <b>Android 2.2</b> (API 8). This is also the minimum API Level required for the provided samples to run. See the &lt;uses-sdk android:minSdkVersion="8"/&gt; tag in their <b>AndroidManifest.xml</b> files. But for successful compilation the <b>target</b> platform should be set to Android 3.0 (API 11) or higher. It will not prevent them from running on Android 2.2.</p>
<div class="image">
<img src="../../android_sdk_and_avd_manager.png" alt="android_sdk_and_avd_manager.png"/>
</div>
<p class="startli">See <a href="http://developer.android.com/sdk/installing/adding-packages.html">Adding Platforms and Packages</a> for help with installing/updating SDK components.</p>
</li>
</ul>
</li>
<li><p class="startli"><b>Eclipse IDE</b></p>
<p class="startli">Check the <a href="http://developer.android.com/sdk/requirements.html">Android SDK System Requirements</a> document for a list of Eclipse versions that are compatible with the Android SDK. For OpenCV 2.4.x we recommend <b>Eclipse 3.7 (Indigo)</b> or <b>Eclipse 4.2 (Juno)</b>. They work well for OpenCV under both Windows and Linux.</p>
<p class="startli">If you have no Eclipse installed, you can get it from the <a href="http://www.eclipse.org/downloads/">official site</a>.</p>
</li>
<li><p class="startli"><b>ADT plugin for Eclipse</b></p>
<p class="startli">These instructions are copied from <a href="http://developer.android.com/sdk/installing/installing-adt.html">Android Developers site</a>, check it out in case of any ADT-related problem.</p>
<p class="startli">Assuming that you have Eclipse IDE installed, as described above, follow these steps to download and install the ADT plugin:</p><ol type="a">
<li>Start Eclipse, then select Help &ndash;&gt; Install New Software...</li>
<li>Click Add (in the top-right corner).</li>
<li>In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location: <a href="https://dl-ssl.google.com/android/eclipse/">https://dl-ssl.google.com/android/eclipse/</a></li>
<li><p class="startli">Click OK</p>
<dl class="section note"><dt>Note</dt><dd>If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).</dd></dl>
</li>
<li>In the Available Software dialog, select the checkbox next to Developer Tools and click Next.</li>
<li><p class="startli">In the next window, you'll see a list of the tools to be downloaded. Click Next.</p>
<dl class="section note"><dt>Note</dt><dd>If you also plan to develop native C++ code with Android NDK don't forget to enable NDK Plugins installations as well.</dd></dl>
<div class="image">
<img src="../../eclipse_inst_adt.png" alt="eclipse_inst_adt.png"/>
</div>
</li>
<li><p class="startli">Read and accept the license agreements, then click Finish.</p>
<dl class="section note"><dt>Note</dt><dd>If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.</dd></dl>
</li>
<li>When the installation completes, restart Eclipse.</li>
</ol>
</li>
</ol>
<h3>Native development in C++</h3>
<p>You need the following software to be installed in order to develop for Android in C++:</p>
<ol type="1">
<li><p class="startli"><b>Android NDK</b></p>
<p class="startli">To compile C++ code for Android platform you need Android Native Development Kit (<em>NDK</em>).</p>
<p class="startli">You can get the latest version of NDK from the <a href="http://developer.android.com/tools/sdk/ndk/index.html">download page</a>. To install Android NDK just extract the archive to some folder on your computer. Here are <a href="http://developer.android.com/tools/sdk/ndk/index.html#Installing">installation instructions</a>.</p>
<dl class="section note"><dt>Note</dt><dd>Before start you can read official Android NDK documentation which is in the Android NDK archive, in the folder <code>docs/</code>. The main article about using Android NDK build system is in the <code>ANDROID-MK.html</code> file. Some additional information you can find in the <code>APPLICATION-MK.html</code>, <code>NDK-BUILD.html</code> files, and <code>CPU-ARM-NEON.html</code>, <code>CPLUSPLUS-SUPPORT.html</code>, <code>PREBUILTS.html</code>.</dd></dl>
</li>
<li><p class="startli"><b>CDT plugin for Eclipse</b></p>
<p class="startli">If you selected for installation the NDK plugins component of Eclipse ADT plugin (see the picture above) your Eclipse IDE should already have CDT plugin (that means C/C++ Development Tooling). There are several possible ways to integrate compilation of C++ code by Android NDK into Eclipse compilation process. We recommend the approach based on Eclipse CDT(C/C++ Development Tooling) Builder.</p>
</li>
</ol>
<h2>Android application structure </h2>
<p>Usually source code of an Android application has the following structure:</p>
<ul>
<li><code>root folder of the project/</code><ul>
<li><code>jni/</code></li>
<li><code>libs/</code></li>
<li><code>res/</code></li>
<li><code>src/</code></li>
<li><code>AndroidManifest.xml</code></li>
<li><code>project.properties</code></li>
<li><code>... other files ...</code></li>
</ul>
</li>
</ul>
<p>Where:</p>
<ul>
<li>the <code>src</code> folder contains Java code of the application,</li>
<li>the <code>res</code> folder contains resources of the application (images, xml files describing UI layout, etc),</li>
<li>the <code>libs</code> folder will contain native libraries after a successful build,</li>
<li>and the <code>jni</code> folder contains C/C++ application source code and NDK's build scripts <code>Android.mk</code> and <code>Application.mk</code> producing the native libraries,</li>
<li><p class="startli"><code>AndroidManifest.xml</code> file presents essential information about application to the Android system (name of the Application, name of main application's package, components of the application, required permissions, etc).</p>
<p class="startli">It can be created using Eclipse wizard or android tool from Android SDK.</p>
</li>
<li><code>project.properties</code> is a text file containing information about target Android platform and other build details. This file is generated by Eclipse or can be created with android tool included in Android SDK.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>Both <code>AndroidManifest.xml</code> and <code>project.properties</code> files are required to compile the C++ part of the application, since Android NDK build system relies on them. If any of these files does not exist, compile the Java part of the project before the C++ part.</dd></dl>
<h2><code>Android.mk</code> and <code>Application.mk</code> scripts </h2>
<p>The script <code>Android.mk</code> usually has the following structure: </p><div class="fragment"><div class="line">LOCAL_PATH := \f$(call my-dir)</div><div class="line"></div><div class="line">include \f$(CLEAR_VARS)</div><div class="line">LOCAL_MODULE    := &lt;module_name&gt;</div><div class="line">LOCAL_SRC_FILES := &lt;list of .c and .cpp project files&gt;</div><div class="line">&lt;some variable name&gt; := &lt;some variable value&gt;</div><div class="line">...</div><div class="line">&lt;some variable name&gt; := &lt;some variable value&gt;</div><div class="line"></div><div class="line">include \f$(BUILD_SHARED_LIBRARY)</div></div><!-- fragment --><p> This is the minimal file <code>Android.mk</code>, which builds C++ source code of an Android application. Note that the first two lines and the last line are mandatory for any <code>Android.mk</code>.</p>
<p>Usually the file <code>Application.mk</code> is optional, but in case of project using OpenCV, when STL and exceptions are used in C++, it also should be created. Example of the file <code>Application.mk</code>: </p><div class="fragment"><div class="line">APP_STL := gnustl_static</div><div class="line">APP_CPPFLAGS := -frtti -fexceptions</div><div class="line">APP_ABI := all</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>We recommend setting APP_ABI := all for all targets. If you want to specify the target explicitly, use armeabi for ARMv5/ARMv6, armeabi-v7a for ARMv7, x86 for Intel Atom or mips for MIPS.</dd></dl>
<p><a class="anchor" id="tutorial_android_dev_intro_ndk"></a></p><h2>Building application native part from command line </h2>
<p>Here is the standard way to compile C++ part of an Android application:</p>
<p><b>warning</b></p>
<p>We strongly recommend using cmd.exe (standard Windows console) instead of Cygwin on <b>Windows</b>. Use the latter if only you're absolutely sure about, what you're doing. Cygwin is not really supported and we are unlikely to help you in case you encounter some problems with it. So, use it only if you're capable of handling the consequences yourself.</p>
<ol type="1">
<li>Open console and go to the root folder of an Android application <div class="fragment"><div class="line">cd &lt;root folder of the project&gt;/</div></div><!-- fragment --></li>
<li>Run the following command <div class="fragment"><div class="line">&lt;path_where_NDK_is_placed&gt;/ndk-build</div></div><!-- fragment --> <dl class="section note"><dt>Note</dt><dd>On Windows we recommend to use ndk-build.cmd in standard Windows console (cmd.exe) rather than the similar bash script in Cygwin shell. <div class="image">
<img src="../../ndk_build.png" alt="ndk_build.png"/>
</div>
</dd></dl>
</li>
<li>After executing this command the C++ part of the source code is compiled.</li>
</ol>
<p>After that the Java part of the application can be (re)compiled (using either <em>Eclipse</em> or <em>Ant</em> build tool).</p>
<dl class="section note"><dt>Note</dt><dd>Some parameters can be set for the ndk-build: <b>Example 1</b>: Verbose compilation <div class="fragment"><div class="line">&lt;path_where_NDK_is_placed&gt;/ndk-build V=1</div></div><!-- fragment --> <b>Example 2</b>: Rebuild all <div class="fragment"><div class="line">&lt;path_where_NDK_is_placed&gt;/ndk-build -B</div></div><!-- fragment --></dd></dl>
<p><a class="anchor" id="tutorial_android_dev_intro_eclipse"></a></p><h2>Building application native part from <em>Eclipse</em> (CDT Builder) </h2>
<p>There are several possible ways to integrate compilation of native C++ code by Android NDK into Eclipse build process. We recommend the approach based on Eclipse CDT(C/C++ Development Tooling) Builder.</p>
<p><b>important</b></p>
<p>OpenCV for Android package since version 2.4.2 contains sample projects pre-configured CDT Builders. For your own projects follow the steps below.</p>
<ol type="1">
<li><p class="startli">Define the NDKROOT environment variable containing the path to Android NDK in your system (e.g. "X:\\Apps\\android-ndk-r8" or "/opt/android-ndk-r8").</p>
<p class="startli"><b>On Windows</b> an environment variable can be set via My Computer -&gt; Properties -&gt; Advanced -&gt; Environment variables. On Windows 7 it's also possible to use <a href="http://ss64.com/nt/setx.html">setx</a> command in a console session.</p>
<p class="startli"><b>On Linux</b> and <b>MacOS</b> an environment variable can be set via appending a "export VAR_NAME=VAR_VALUE" line to the <code>"~/.bashrc"</code> file and logging off and then on.</p>
<dl class="section note"><dt>Note</dt><dd>It's also possible to define the NDKROOT environment variable within Eclipse IDE, but it should be done for every new workspace you create. If you prefer this option better than setting system environment variable, open Eclipse menu Window -&gt; Preferences -&gt; C/C++ -&gt; Build -&gt; Environment, press the Add... button and set variable name to NDKROOT and value to local Android NDK path. #. After that you need to <b>restart Eclipse</b> to apply the changes.</dd></dl>
</li>
<li>Open Eclipse and load the Android app project to configure.</li>
<li>Add C/C++ Nature to the project via Eclipse menu New -&gt; Other -&gt; C/C++ -&gt; Convert to a C/C++ Project. <div class="image">
<img src="../../eclipse_cdt_cfg1.png" alt="eclipse_cdt_cfg1.png"/>
</div>
 And: <div class="image">
<img src="../../eclipse_cdt_cfg2.png" alt="eclipse_cdt_cfg2.png"/>
</div>
</li>
<li>Select the project(s) to convert. Specify "Project type" = Makefile project, "Toolchains" = Other Toolchain. <div class="image">
<img src="../../eclipse_cdt_cfg3.png" alt="eclipse_cdt_cfg3.png"/>
</div>
</li>
<li><p class="startli">Open Project Properties -&gt; C/C++ Build, uncheck Use default build command, replace "Build
    command" text from "make" to</p>
<p class="startli">"${NDKROOT}/ndk-build.cmd" on Windows,</p>
<p class="startli">"${NDKROOT}/ndk-build" on Linux and MacOS.</p>
<div class="image">
<img src="../../eclipse_cdt_cfg4.png" alt="eclipse_cdt_cfg4.png"/>
</div>
</li>
<li><p class="startli">Go to Behaviour tab and change "Workbench build type" section like shown below:</p>
<div class="image">
<img src="../../eclipse_cdt_cfg5.png" alt="eclipse_cdt_cfg5.png"/>
</div>
</li>
<li><p class="startli">Press OK and make sure the ndk-build is successfully invoked when building the project.</p>
<div class="image">
<img src="../../eclipse_cdt_cfg6.png" alt="eclipse_cdt_cfg6.png"/>
</div>
</li>
<li><p class="startli">If you open your C++ source file in Eclipse editor, you'll see syntax error notifications. They are not real errors, but additional CDT configuring is required.</p>
<div class="image">
<img src="../../eclipse_cdt_cfg7.png" alt="eclipse_cdt_cfg7.png"/>
</div>
</li>
<li><p class="startli">Open Project Properties -&gt; C/C++ General -&gt; Paths and Symbols and add the following <b>Include</b> paths for **C++**: </p><div class="fragment"><div class="line"># for NDK r8 and prior:</div><div class="line">${NDKROOT}/platforms/android-9/arch-arm/usr/include</div><div class="line">${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include</div><div class="line">${NDKROOT}/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include</div><div class="line">${ProjDirPath}/../../sdk/native/jni/include</div><div class="line"></div><div class="line"># for NDK r8b and later:</div><div class="line">${NDKROOT}/platforms/android-9/arch-arm/usr/include</div><div class="line">${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include</div><div class="line">${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include</div><div class="line">${ProjDirPath}/../../sdk/native/jni/include</div></div><!-- fragment --><p> The last path should be changed to the correct absolute or relative path to OpenCV4Android SDK location.</p>
<p class="startli">This should clear the syntax error notifications in Eclipse C++ editor.</p>
<div class="image">
<img src="../../eclipse_cdt_cfg8.png" alt="eclipse_cdt_cfg8.png"/>
</div>
</li>
</ol>
<h2>Debugging and Testing </h2>
<p>In this section we will give you some easy-to-follow instructions on how to set up an emulator or hardware device for testing and debugging an Android project.</p>
<h3>AVD</h3>
<p>AVD (<em>Android Virtual Device</em>) is not probably the most convenient way to test an OpenCV-dependent application, but sure the most uncomplicated one to configure.</p>
<ol type="1">
<li>Assuming you already have <em>Android SDK</em> and <em>Eclipse IDE</em> installed, in Eclipse go Window -&gt; AVD Manager.</li>
<li>Press the New button in AVD Manager window.</li>
<li><p class="startli">Create new Android Virtual Device window will let you select some properties for your new device, like target API level, size of SD-card and other.</p>
<div class="image">
<img src="../../AVD_create.png" alt="AVD_create.png"/>
</div>
</li>
<li>When you click the Create AVD button, your new AVD will be available in AVD Manager.</li>
<li>Press Start to launch the device. Be aware that any AVD (a.k.a. Emulator) is usually much slower than a hardware Android device, so it may take up to several minutes to start.</li>
<li>Go Run -&gt; Run/Debug in Eclipse IDE to run your application in regular or debugging mode. Device Chooser will let you choose among the running devices or to start a new one.</li>
</ol>
<h3>Hardware Device</h3>
<p>If you have an Android device, you can use it to test and debug your applications. This way is more authentic, though a little bit harder to set up. You need to make some actions for Windows and Linux operating systems to be able to work with Android devices. No extra actions are required for Mac OS. See detailed information on configuring hardware devices in subsections below.</p>
<p>You may also consult the official <a href="http://developer.android.com/tools/device.html">Android Developers site instructions</a> for more information.</p>
<h4>Windows host computer</h4>
<ol type="1">
<li>Enable USB debugging on the Android device (via Settings menu).</li>
<li>Attach the Android device to your PC with a USB cable.</li>
<li>Go to Start Menu and <b>right-click</b> on Computer. Select Manage in the context menu. You may be asked for Administrative permissions.</li>
<li><p class="startli">Select Device Manager in the left pane and find an unknown device in the list. You may try unplugging it and then plugging back in order to check whether it's your exact equipment appears in the list.</p>
<div class="image">
<img src="../../usb_device_connect_01.png" alt="usb_device_connect_01.png"/>
</div>
</li>
<li><p class="startli">Try your luck installing Google USB drivers without any modifications: <b>right-click</b> on the unknown device, select Properties menu item &ndash;&gt; Details tab &ndash;&gt; Update Driver button.</p>
<div class="image">
<img src="../../usb_device_connect_05.png" alt="usb_device_connect_05.png"/>
</div>
</li>
<li><p class="startli">Select Browse computer for driver software.</p>
<div class="image">
<img src="../../usb_device_connect_06.png" alt="usb_device_connect_06.png"/>
</div>
</li>
<li><p class="startli">Specify the path to <code>&lt;Android SDK folder&gt;/extras/google/usb_driver/</code> folder.</p>
<div class="image">
<img src="../../usb_device_connect_07.png" alt="usb_device_connect_07.png"/>
</div>
</li>
<li><p class="startli">If you get the prompt to install unverified drivers and report about success - you've finished with USB driver installation.</p>
<div class="image">
<img src="../../usb_device_connect_08.png" alt="usb_device_connect_08.png"/>
</div>
<div class="image">
<img src="../../usb_device_connect_09.png" alt="usb_device_connect_09.png"/>
</div>
</li>
<li><p class="startli">Otherwise (getting the failure like shown below) follow the next steps.</p>
<div class="image">
<img src="../../usb_device_connect_12.png" alt="usb_device_connect_12.png"/>
</div>
</li>
<li><p class="startli">Again <b>right-click</b> on the unknown device, select Properties &ndash;&gt; Details &ndash;&gt; Hardware Ids and copy the line like <code>USB\VID_XXXX&amp;PID_XXXX&amp;MI_XX</code>.</p>
<div class="image">
<img src="../../usb_device_connect_02.png" alt="usb_device_connect_02.png"/>
</div>
</li>
<li><p class="startli">Now open file <code>&lt;Android SDK folder&gt;/extras/google/usb_driver/android_winusb.inf</code>. Select either Google.NTx86 or Google.NTamd64 section depending on your host system architecture.</p>
<div class="image">
<img src="../../usb_device_connect_03.png" alt="usb_device_connect_03.png"/>
</div>
</li>
<li><p class="startli">There should be a record like existing ones for your device and you need to add one manually.</p>
<div class="image">
<img src="../../usb_device_connect_04.png" alt="usb_device_connect_04.png"/>
</div>
</li>
<li><p class="startli">Save the <code>android_winusb.inf</code> file and try to install the USB driver again.</p>
<div class="image">
<img src="../../usb_device_connect_05.png" alt="usb_device_connect_05.png"/>
</div>
<div class="image">
<img src="../../usb_device_connect_06.png" alt="usb_device_connect_06.png"/>
</div>
<div class="image">
<img src="../../usb_device_connect_07.png" alt="usb_device_connect_07.png"/>
</div>
</li>
<li><p class="startli">This time installation should go successfully.</p>
<div class="image">
<img src="../../usb_device_connect_08.png" alt="usb_device_connect_08.png"/>
</div>
<div class="image">
<img src="../../usb_device_connect_09.png" alt="usb_device_connect_09.png"/>
</div>
</li>
<li><p class="startli">And an unknown device is now recognized as an Android phone.</p>
<div class="image">
<img src="../../usb_device_connect_10.png" alt="usb_device_connect_10.png"/>
</div>
</li>
<li><p class="startli">Successful device USB connection can be verified in console via adb devices command.</p>
<div class="image">
<img src="../../usb_device_connect_11.png" alt="usb_device_connect_11.png"/>
</div>
</li>
<li>Now, in Eclipse go Run -&gt; Run/Debug to run your application in regular or debugging mode. Device Chooser will let you choose among the devices.</li>
</ol>
<h4>Linux host computer</h4>
<p>By default Linux doesn't recognize Android devices, but it's easy to fix this issue. On Ubuntu Linux you have to create a new **/etc/udev/rules.d/51-android.rules** configuration file that contains information about your Android device. You may find some Vendor ID's <a href="http://developer.android.com/tools/device.html#VendorIds">here</a> or execute lsusb command to view VendorID of plugged Android device. Here is an example of such file for LG device: </p><div class="fragment"><div class="line">SUBSYSTEM==&quot;usb&quot;, ATTR{idVendor}==&quot;1004&quot;,  MODE=&quot;0666&quot;, GROUP=&quot;plugdev&quot;</div></div><!-- fragment --><p> Then restart your adb server (even better to restart the system), plug in your Android device and execute adb devices command. You will see the list of attached devices:</p>
<div class="image">
<img src="../../usb_device_connect_ubuntu.png" alt="usb_device_connect_ubuntu.png"/>
</div>
<h4>Mac OS host computer</h4>
<p>No actions are required, just connect your device via USB and run adb devices to check connection.</p>
<h2>What's next </h2>
<p>Now, when you have your development environment set up and configured, you may want to proceed to installing OpenCV4Android SDK. You can learn how to do that in a separate <a class="el" href="../../da/d2a/tutorial_O4A_SDK.html">OpenCV4Android SDK</a> tutorial. </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:36 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
